import requests

from background.run_backrounds import run_all_bg
from authorization import do_login, do_register, do_logout
from message.sendmessage import send_message_private


run_all_bg()
login_user_name = ""


def run_server():
    global login_user_name
    while True:
        from config import settings
        if not settings.IsLogined:
            input_operation = input("请输入指令：1 注册  2 登录\n")
            if input_operation == "1":
                user_name = input("请输入用户名\n")
                password = input("请输入用密码\n")
                password2 = input("请重复密码\n")
                do_register(user_name=user_name, password=password, password2=password2)

            if input_operation == "2":
                user_name = input("请输入用户名\n")
                password = input("请输入用密码\n")
                result = do_login(user_name=user_name, password=password)
                if result:
                    login_user_name = user_name
        else:
            input_operation = input("请输入指令：1 发送消息  2 登出\n")
            if input_operation == "1":
                to_name = input("请输入对方名称\n")
                message = input("请输入消息内容\n")
                send_message_private(login_user_name, to_name, message)
            if input_operation == "2":
                do_logout()


if __name__ == '__main__':
    run_server()
